package com.dai.zhenfujin.visitingcard.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dai.zhenfujin.R;
import com.dai.zhenfujin.visitingcard.bean.ParticularsPageBean;

import java.util.List;

public class ParticularsPageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    /**
     *  头部信息
      */
    public static final int HEAD = 0;

    /**
     *基本信息  basic information
     */
    public static final int BASIC_INFORMATION = 1;
    /**
     * 房屋概况tenement
     */
    public static final int TENEMENT = 2;

    /**
     * 其他产品 other products
     */
    public static final int OTHER_PRODUCTS = 3;
    /***
     * 当前类型
     */
     public int currentType = HEAD;

    private Context context;
    private List<ParticularsPageBean> beans;
    private LayoutInflater inflater ;

    public ParticularsPageAdapter(Context context, List<ParticularsPageBean> beans) {
        this.context = context;
        this.beans = beans;
        inflater = LayoutInflater.from(context);
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == HEAD){
            return new HeadViewHolder(inflater.inflate(R.layout.pp_head_viewpager,null),context);
        }
//        lse if(viewType ==BASIC_INFORMATION ){
//            return new BasicInformationViewHolder(inflater.inflate(R.layout.pp_basic_information,null));
//        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ParticularsPageBean bean = beans.get(position);

        if(getItemViewType(position) == HEAD){
            HeadViewHolder headViewHolder = (HeadViewHolder) holder;
            headViewHolder.tvName.setText(bean.getName());
            headViewHolder.tvPosition.setText(bean.getPosition());
            headViewHolder.tvBloc.setText(bean.getBloc());
            headViewHolder.tvCommpany.setText(bean.getCompany());
            headViewHolder.tvType.setText(bean.getType());
            headViewHolder.tvPrice.setText(bean.getPrice());
            headViewHolder.tvRoomSetup.setText(bean.getRoomsetup());
            headViewHolder.tvCentiare.setText(bean.getCentiare());

            headViewHolder.tvHowmuch.setText(bean.getHowmuch());
            headViewHolder.tvOrientation.setText(bean.getOrientation());
            headViewHolder.tvFloor.setText(bean.getFloor());
            headViewHolder.tvTime.setText(bean.getTime());
            headViewHolder.tvElevator.setText(bean.getElevator());
            headViewHolder.tvTypetwo.setText(bean.getTypetwo());
            headViewHolder.tvBuildingNames.setText(bean.getBuildingnames());
            headViewHolder.tvHousingSituation.setText(bean.getHousingsituation());


        }
//        else if(getItemViewType(position)== BASIC_INFORMATION){
//
//        }/
    }





    class HeadViewHolder extends RecyclerView.ViewHolder{
        private Context context;
        private TextView tvName,tvPosition, tvBloc, tvCommpany, tvType, tvPrice, tvRoomSetup, tvCentiare
                ,tvHowmuch, tvOrientation,tvFloor,tvTime,tvElevator,tvTypetwo, tvBuildingNames,tvHousingSituation;

        public HeadViewHolder(View itemView, Context context) {
            super(itemView);
            this.context =context;
            tvName = itemView.findViewById(R.id.pp_adapter_name);//姓名
            tvPosition = itemView.findViewById(R.id.pp_adapter_position);//职位
            tvBloc = itemView.findViewById(R.id.pp_adapter_bloc);//集团
            tvCommpany = itemView.findViewById(R.id.pp_adapter_company);//公司
            tvType = itemView.findViewById(R.id.pp_adapter_type);//类型
            tvPrice = itemView.findViewById(R.id.pp_adapter_price);//价格
            tvRoomSetup = itemView.findViewById(R.id.pp_adapter_room_setup);//几室几厅几卫
            tvCentiare = itemView.findViewById(R.id.pp_adapter_centiare);//平方米

            tvHowmuch = itemView.findViewById(R.id.pp_adapter_howmuch);//单价
            tvOrientation = itemView.findViewById(R.id.pp_adapter_orientation);//朝向
            tvFloor = itemView.findViewById(R.id.pp_adapter_floor);//楼层
            tvTime = itemView.findViewById(R.id.pp_adapter_time);//开盘时间
            tvElevator = itemView.findViewById(R.id.pp_adapter_elevator);//是否有电梯
            tvTypetwo = itemView.findViewById(R.id.pp_adapter_typetwo);//类型 （普通住宅）
            tvBuildingNames = itemView.findViewById(R.id.pp_adapter_buildingnames);//所属楼盘
            tvHousingSituation = itemView.findViewById(R.id.pp_adapter_housingsituation);//房屋概况
        }
    }



//    class BasicInformationViewHolder extends RecyclerView.ViewHolder{
//
////        private TextView tvPrice,tvRoomSetup,tvCentiare,tvHowmuch,
////        tvOrientation,tvFloor,tvTime,tvElevator,tvTypetwo,
////        tvBuildingNames;
//             //   tvHousingSituation;
//        public BasicInformationViewHolder(@NonNull View itemView) {
//            super(itemView);
//
//          // tvHousingSituation = itemView.findViewById(R.id.pp_adapter_price);
//        }
//    }
    @Override
    public int getItemCount() {
        return beans.size();
    }

    @Override
    public int getItemViewType(int position) {
        switch (position){
            case HEAD:
                currentType = HEAD;//头部信息
                break;
            case BASIC_INFORMATION:
                currentType = BASIC_INFORMATION;//基本信息
                break;
            case TENEMENT:
                currentType = TENEMENT;//房屋概况
                break;
            case OTHER_PRODUCTS:
                currentType = OTHER_PRODUCTS;//其他产品
                break;
        }
        return currentType;
    }
}
